using System;
using System.Collections.Generic;
using System.Text;
using TelnetExpect;
using System.Windows.Forms;
using System.Diagnostics;

namespace TelnetExpect
{
    public class WinFormsAuthenticationNtlmTelnetHandler : AuthenticationNtlmTelnetHandler
    {
        Form m_parent;

        //----
        public WinFormsAuthenticationNtlmTelnetHandler(Form owner)
            : this(owner, null)
        {
        }

        public WinFormsAuthenticationNtlmTelnetHandler(Form owner, bool? promptOrForce)
            : base(promptOrForce)
        {
            if (owner == null)
                throw new ArgumentNullException("owner", "Need owner Form to display MessageBox on.");
            m_parent = owner;
        }

        //----
        protected override bool Prompt(string message)
        {

            DialogResult rslt = DialogResult.None;
            EventHandler d = delegate {
                rslt = MessageBox.Show(m_parent, message, "Authentication by NTLM (TNAP)",
                    MessageBoxButtons.YesNo);
            };
            if (m_parent.InvokeRequired) {
                m_parent.Invoke(d);
            } else {
                d.Invoke(null, null);
            }
            Debug.Assert((rslt == DialogResult.Yes) || (rslt == DialogResult.No), "YorN");
            return (rslt == DialogResult.Yes);
        }

    }
}
